<script setup>
import { ref } from 'vue'
import { onMounted } from 'vue'

//导入图标
import { HomeFilled, Tools, School, Money, Avatar, Expand, Fold, ArrowDown,DocumentChecked } from '@element-plus/icons-vue'
//导入面包屑组件
import Breadcrumb from '../../components/Breadcrumb.vue'
import Dashboard from '../../components/Dashboard.vue'
import router from '../../router'
//判断折叠按钮是否显示
const isCollapse = ref(false)
//定义系统标题是否显示
const title = ref(true)

//定义用户信息
const user = ref({})

onMounted(() => {
    const userStr = localStorage.getItem('user')
    if (userStr) {
        user.value = JSON.parse(userStr);
    }
})

//退出登录
const logout = () => {
    localStorage.removeItem('user')
    router.push('/')
}

//控制左侧菜单的展开与显示
const collapse = () => {
    isCollapse.value = !isCollapse.value
    if (isCollapse.value) {
        isCollapse.value = true
        title.value = false
    } else {
        title.value = false
    }
}
</script>
<template>
    <div class="common-layout">
        <el-container>
            <el-aside :width="isCollapse ? '64px' : '200px'">
                <div class="system-title">
                    <img src="../../assets/sximages/logo.png" />
                    <span>软件工程学院</span>
                </div>
                <el-menu default-active="home" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
                    :collapse="isCollapse" unique-opened :collapse-transition="collapse - transition" router>

                    <el-menu-item index="home">
                        <el-icon>
                            <HomeFilled />
                        </el-icon>
                        <template #title>
                            <span>首页</span>
                        </template>
                    </el-menu-item>
                    <el-sub-menu index="2">
                        <template #title>
                            <el-icon>
                                <Tools />
                            </el-icon>
                            <span>系统管理</span>
                        </template>
                        <el-menu-item index="/user">用户管理</el-menu-item>
                        <el-menu-item index="/notice">通知公告</el-menu-item>
                        <el-menu-item index="1-3">专业管理</el-menu-item>
                        <el-sub-menu index="1-4">
                            <template #title>
                                <span>班级管理</span>
                            </template>
                            <el-menu-item index="/clazz">班级维护</el-menu-item>
                        </el-sub-menu>
                    </el-sub-menu>
                    <el-sub-menu index="3">
                        <template #title>
                            <el-icon>
                                <School />
                            </el-icon>
                            <span>宿舍管理</span>
                        </template>
                        <el-menu-item index="2-1">宿舍信息</el-menu-item>
                        <el-menu-item index="2-2">入住管理</el-menu-item>
                    </el-sub-menu>

                    <el-sub-menu index="4">
                        <template #title>
                            <el-icon>
                                <Money />
                            </el-icon>
                            <span>财务管理</span>
                        </template>
                        <el-menu-item index="3-1">缴费管理</el-menu-item>
                        <el-menu-item index="3-2">缴费记录</el-menu-item>
                    </el-sub-menu>
                    <el-sub-menu index="5">
                        <template #title>
                            <el-icon>
                                <Avatar />
                            </el-icon>
                            <span>学生管理</span>
                        </template>
                        <el-menu-item index="4-1">学生信息</el-menu-item>
                        <el-menu-item index="4-2">报道信息</el-menu-item>
                    </el-sub-menu>
                    <el-sub-menu index="reporting">
                        <template #title>
                            <el-icon>
                                <DocumentChecked />
                            </el-icon>
                            <span>报到管理</span>
                        </template>
                        <el-menu-item index="/reporting">报到查询</el-menu-item>
                    </el-sub-menu>
                </el-menu>
            </el-aside>
            <el-container>
                <el-header>
                    <div class="collapse" @click="collapse">
                        <el-icon :size="28" v-if="isCollapse" style="cursor: pointer;">
                            <Expand />
                        </el-icon>
                        <el-icon :size="28" v-if="!isCollapse" style="cursor: pointer;">
                            <Fold />
                        </el-icon>
                    </div>
                    <span>新生报到服务平台</span>
                    <!--右侧用户信息-->
                    <div class="user-info">
                        <img src="../../assets/sximages//u169.svg" />
                        <el-dropdown>
                            <span class="el-dropdown-link">
                                {{ user.username }}
                                <el-icon>
                                    <ArrowDown />
                                </el-icon>
                            </span>
                            <template #dropdown>
                                <el-dropdown-menu style="margin-top: 5px;">
                                    <el-dropdown-item>个人信息</el-dropdown-item>
                                    <el-dropdown-item>修改密码</el-dropdown-item>
                                    <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                                </el-dropdown-menu>
                            </template>
                        </el-dropdown>
                    </div>
                </el-header>
                <!-- 主体部分 -->
                <el-main>
                    <!-- 面包屑组件 -->
                    <Breadcrumb></Breadcrumb>
                    <!-- 仪表盘组件 -->
                    <Dashboard v-if="$route.path === '/home'"></Dashboard>
                    <!-- 路由视图 -->
                    <router-view></router-view>
                </el-main>
                <el-footer>Footer</el-footer>
            </el-container>
        </el-container>
    </div>
</template>
<style scoped>
.common-layout {
    width: 100vw;
    height: 100%;
}

.el-aside {
    color: #333;
    line-height: 200px;
    overflow: hidden;
}

.el-header {
    background-color: rgb(242, 243, 245);
    color: #333;
    display: flex;
    line-height: 60px;
    padding: 0;
}

.el-main {
    background-color: #E9EEF3;
    color: #333;
    height: 625px;
}

.el-footer {
    background-color: #fefdf9;
    color: #333;
    text-align: center;
    line-height: 35px;
    height: 35px !important;
}

.system-title {
    width: 200px;
    height: 60px;
    background-color: rgb(143, 1, 0);
    line-height: 60px;
    position: relative;
    color: white;
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    text-indent: 48px;
}

.system-title img {
    width: 50px;
    position: absolute;
    left: 10px;
    top: 5px;
}

.collapse {
    padding-top: 10px;
    padding-left: 10px;
    line-height: 60px;
}

.el-header span {
    display: inline-block;
    line-height: 60px;
    font-size: 20px;
    margin-left: 10px;
}

.user-info {
    position: absolute;
    right: 150px;
    top: 10px;
}

.user-info {
    position: absolute;
    right: 10px;
    top: 5px;
    font-size: 2px;
}

:deep() .el-dropdown-link {
    outline: none;
    cursor: pointer;
    font-size: 24px;
}
</style>